package cn.team11.smarteye.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import cn.team11.sds.dayi.R;
import com.bumptech.glide.Glide;

import net.lucode.hackware.magicindicator.buildins.UIUtil;

import java.util.List;

import cn.team11.smarteye.bean.CaptureInfo;

/**
 * Created by Murphy on 2017/11/20.
 */

public class CaptureScreenGridAdapter extends BaseAdapter{

    private List<CaptureInfo> mDatas;
    private Context mContext;

    private boolean isEditable;

    public CaptureScreenGridAdapter(List<CaptureInfo> mDatas, Context mContext) {
        this.mDatas = mDatas;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public CaptureInfo getItem(int i) {
        return mDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null){
            holder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.capture_screen_shot_item, null);
            holder.img = (ImageView) view.findViewById(R.id.screen_shot_item);
            holder.select_status = (ImageView) view.findViewById(R.id.screen_shot_check_status);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        Glide.with(mContext).load(mDatas.get(i).getPath()).override(UIUtil.dip2px(mContext, 150), UIUtil.dip2px(mContext, 150)).into(holder.img);

        if (isEditable){
            holder.select_status.setVisibility(View.VISIBLE);
            holder.select_status.setSelected(mDatas.get(i).isSelected());
        } else {
            mDatas.get(i).setSelected(false);
            holder.select_status.setVisibility(View.INVISIBLE);
            holder.select_status.setSelected(false);
        }

        return view;
    }

    public void setEditMode(boolean editMode){
        this.isEditable = editMode;
        notifyDataSetChanged();
    }

    public class ViewHolder
    {
        public ImageView img;
        public ImageView select_status;
    }

}
